<template>
  <div class="login-con clearfix">
    <h1>注册账号</h1>
    <el-form
      ref="formData"
      :model="formData"
      label-width="80px"
      @submit.native.prevent="submitForm"
    >
      <el-form-item label="用户名" prop="username">
        <el-input
          v-model="formData.username"
          placeholder="请输入用户名"
        ></el-input>
      </el-form-item>
      <el-form-item label="手机" prop="phone">
        <el-input v-model="formData.phone" placeholder="请输入手机"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          type="password"
          v-model="formData.password"
          placeholder="请输入密码"
        ></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="password">
        <el-input
          type="password"
          v-model="formData.password2"
          placeholder="请输入密码"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" native-type="submit">注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      formData: {
        username: "",
        phone: "",
        password: "",
        password2: "",
      },
    };
  },

  inject: ["imageUrl", "serviceUrl"],

  methods: {
    submitForm() {
      let that = this;

      axios
        .post(that.serviceUrl + "/sys/user/add", that.formData)
        .then((resp) => {
          console.log(resp);
          if (resp.data.success) {
            that.$router.push("/login");

          } else {
            that.$message.error(resp.data.message);
          }
        })
        .catch((error) => {
          //console.log(error);
        });
    },
  },
};
</script>
